home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!usenet
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: How do I change the middle of a file?
- Date: Fri, 29 Mar 1996 13:59:59 -0500
- Organization: Datalytics, Inc
- Message-ID: <315C332F.2648@datalytics.com>
- References: <4jeclc$4ob@felix.cc.gatech.edu>
- NNTP-Posting-Host: 204.62.224.71
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- Matthew W. Culbreth wrote:
- >
- > Howdy,
- >
- > I've got a big text file that acts as a database. I need to be able
- > to search through the file, find a particular line, and change it.
- >
- > I've tried opening the file in (ios::in|ios::app), but now the program
- > won't getline().
- >
- > Any ideas?
- >
- > Thanks,
-
- You'll have to read it, line by line, searching for the line of
- interest. For each line that isn't what you want, copy it to a
- new file. When you find the one you want, write the changed
- version to the new file instead. Finally, copy the rest of the
- lines to the new file. Close both files, delete the original
- file, and rename the new file to the name of the original file.
-
- You should open the original file with an ifstream (the default
- mode should be fine). Open the new file with an ofstream (the
- default mode should be fine).
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc. | stew@datalytics.com
-